<template>
	<u-popup round="20" :show="projectShow">
		<view class="popup-box">
			<view class="box">
				<view class="tilte">添加项目</view>
				<image class="img" src="/static/home/close.png" mode="scaleToFill" @click="close" />
			</view>
			<view class="item" v-for="(item, index) in projectList" :key="index" @click="confirmProject(item)">
				<image v-if="value == item" class="img" src="/static/home/select.png" mode="scaleToFill" />
				<image v-else class="img" src="/static/home/noSelect.png" mode="scaleToFill" />
				<text>{{item.projectName}}</text>
			</view>
		</view>
	</u-popup>

</template>

<script>
	export default {
		data() {
			return {
				projectList: [],
			}
		},
		props: {
			projectShow: {
				type: Boolean,
				default: false
			},
			value: {
				type: Object,
				default: () => {}
			},
		},
		created() {
			this.getProject();
		},
		methods: {
			getProject() {
				this.$api.projectList({}).then(res => {
					if (res.code == 200) {
						console.log(res);
						this.projectList = res.data;
					}
				})
			},
			confirmProject(item) {
				this.$emit('update:value', item)
				this.$emit('confirm', item)
				this.close()
			},
			close() {
				this.$emit('update:projectShow', false)
			}
		}
	}
</script>

<style scoped lang="scss">
	.popup-box {
		padding: 20rpx 32rpx;
		height: 500rpx;

		.box {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-bottom: 30rpx;


			.tilte {
				font-weight: bold;
				font-size: 32rpx;
				color: #1A1A1A;
			}

			.img {
				width: 24rpx;
				height: 24rpx;
			}
		}


		.item {
			display: flex;
			align-items: center;

			.img {
				width: 32rpx;
				height: 32rpx;
				margin-right: 20rpx;
			}
		}
	}
</style>